﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;


namespace BackgroundTest.TestObjects
{
    /// <summary>
    /// This is a game component that implements IUpdateable.
    /// </summary>
    public class TestObjects : Microsoft.Xna.Framework.DrawableGameComponent
    {
        TestZ testObject;

        SpriteFont spriteFont;

        SpriteBatch spriteBatch;

        public TestObjects(Game game, SpriteBatch _spriteBatch)
            : base(game)
        {
            Game.Content.RootDirectory = "Content";
            spriteBatch = _spriteBatch;
        }

        /// <summary>
        /// Allows the game component to perform any initialization it needs to before starting
        /// to run.  This is where it can query for any required services and load content.
        /// </summary>
        public override void Initialize()
        {
            // TODO: Add your initialization code here
            testObject = new TestZ();

            base.Initialize();
        }

        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            testObject.LoadTexture(Game.Content.Load<Texture2D>(@"ForTest/Testmouse"));

            spriteFont = Game.Content.Load<SpriteFont>(@"Fonts/Kootenay");

            base.LoadContent();
        }

        /// <summary>
        /// Allows the game component to update itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public override void Update(GameTime gameTime)
        {
            // TODO: Add your update code here
            testObject.UpdateTestObject(Mouse.GetState().X, Mouse.GetState().Y);

            testObject.SetZ(0.01f * Convert.ToSingle(Mouse.GetState().ScrollWheelValue) / 120);

            base.Update(gameTime);
        }

        public override void Draw(GameTime gameTime)
        {
            //spriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.BackToFront, SaveStateMode.None);

            testObject.Render(spriteBatch);

            spriteBatch.DrawString(spriteFont, "Z-Buffer=" + testObject.ZBuffer, Vector2.Zero, Color.White);

            spriteBatch.End();

            base.Draw(gameTime);
        }
    }
}